// 统一设备模型
import 'package:casdon/modules/home/data/api/ciot_device_api.dart';
import 'package:tuya_home_sdk_flutter/tuya_home_sdk_flutter.dart';

class UnifiedDeviceModel {
  final String pid;
  final String? devId;
  final String name;
  final String? icon;
  final String? uuid;
  final bool isOnline; // 默认离线状态
  final DeviceSource source;
  final dynamic rawData; // 保留原始数据

  // 融合逻辑
  factory UnifiedDeviceModel.fromTuya(ThingSmartDeviceModel tuya) {
    return UnifiedDeviceModel(
      pid: tuya.productId,
      devId: tuya.devId,
      name: tuya.name,
      icon: tuya.iconUrl,
      isOnline: tuya.isOnline,
      uuid: tuya.uuid,
      source: DeviceSource.tuya,
      rawData: tuya,
    );
  }

  factory UnifiedDeviceModel.fromApi(ResponseCiotDeviceApi api) {
    return UnifiedDeviceModel(
      devId: api.id,
      name: api.name,
      pid: api.pid,
      icon: api.imgUrlStr,
      uuid: null,
      isOnline: false, // 默认离线状态
      source: DeviceSource.ciot,
      rawData: api,
    );
  }

  UnifiedDeviceModel({
    required this.pid,
    required this.devId,
    required this.name,
    required this.icon,
    required this.isOnline,
    required this.source,
    required this.rawData,
    required this.uuid,
  });
}

// 设备来源枚举
enum DeviceSource { tuya, ciot }
